package com.rss.inbound.dao.impl;
// default package
// Generated Jan 10, 2013 11:00:14 PM by Hibernate Tools 3.4.0.CR1

import static org.hibernate.criterion.Example.create;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.SessionFactory;

import com.rss.inbound.beans.CntnTag;
import com.rss.inbound.dao.CntnTagDAO;

/**
 * Home object for domain model class CntnTag.
 * @see .CntnTag
 * @author Hibernate Tools
 */
public class CntnTagDAOImpl implements CntnTagDAO{

	private static final Log log = LogFactory.getLog(CntnTagDAOImpl.class);

	private SessionFactory sessionFactory = getSessionFactory();

/*	protected SessionFactory getSessionFactory() {
		try {
			return (SessionFactory) new InitialContext()
					.lookup("SessionFactory");
		} catch (Exception e) {
			log.error("Could not locate SessionFactory in JNDI", e);
			throw new IllegalStateException(
					"Could not locate SessionFactory in JNDI");
		}
	}*/
	
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	public void persist(CntnTag transientInstance) {
		log.debug("persisting CntnTag instance");
		try {
			sessionFactory.getCurrentSession().persist(transientInstance);
			log.debug("persist successful");
		} catch (RuntimeException re) {
			log.error("persist failed", re);
			throw re;
		}
	}

	public void attachDirty(CntnTag instance) {
		log.debug("attaching dirty CntnTag instance");
		try {
			sessionFactory.getCurrentSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	@SuppressWarnings("deprecation")
	public void attachClean(CntnTag instance) {
		log.debug("attaching clean CntnTag instance");
		try {
			sessionFactory.getCurrentSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void delete(CntnTag persistentInstance) {
		log.debug("deleting CntnTag instance");
		try {
			sessionFactory.getCurrentSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public CntnTag merge(CntnTag detachedInstance) {
		log.debug("merging CntnTag instance");
		try {
			CntnTag result = (CntnTag) sessionFactory.getCurrentSession()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public CntnTag findById(int id) {
		log.debug("getting CntnTag instance with id: " + id);
		try {
			CntnTag instance = (CntnTag) sessionFactory.getCurrentSession()
					.get("CntnTag", id);
			if (instance == null) {
				log.debug("get successful, no instance found");
			} else {
				log.debug("get successful, instance found");
			}
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	@SuppressWarnings("unchecked")
	public List<CntnTag> findByExample(CntnTag instance) {
		log.debug("finding CntnTag instance by example");
		try {
			List<CntnTag> results = (List<CntnTag>) sessionFactory
					.getCurrentSession().createCriteria("CntnTag")
					.add(create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}
}
